package com.cqeec.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.cqeec.domain.Student;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import java.awt.Font;
import javax.swing.JMenuItem;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
 *    学生主界面
 * @author 邓学强
 * 功能： 学生查看考勤 请假 修改登录密码
 *
 */
public class StudentInterface extends JFrame {

	private JPanel contentPane;
	private static JLabel label;
	private static StudentInterface frame;
	private static StudentAttend amend=null;
	private static Leaved leaved=null;

	
	/**
	 * Launch the application.
	 */
	public static void main(Student myStudent) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					StudentInterface frame = new StudentInterface(myStudent);
					frame.setVisible(true);String path = "src/img/zsxx_bg.jpg";
					// 背景图片
					ImageIcon background = new ImageIcon(path);
					// 把背景图片显示在一个标签里面
					label = new JLabel(background);

					// 把标签的大小位置设置为图片刚好填充整个面板
					label.setBounds(0, 0, 1044, 648);
					// 把内容窗格转化为JPanel，否则不能用方法setOpaque()来使内容窗格透明
					JPanel imagePanel = (JPanel) frame.getContentPane();
					imagePanel.setOpaque(false);
					// 把背景图片添加到分层窗格的最底层作为背景
					frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
					frame.setResizable(false);// 设置窗体不可拖动
					frame.setVisible(true);
					
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 * @param myStudent 
	 */
	public StudentInterface(Student myStudent) {
	
		
		setTitle("学生主界面");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100,1044, 648);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu menu = new JMenu("学生考勤");
		menu.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 20));
		menuBar.add(menu);
		
		JMenuItem menuItem = new JMenuItem("查看考勤");
		menuItem.addActionListener(new ActionListener() {
			/**
			 * 查看考勤界面
			 */
			
			public void actionPerformed(ActionEvent arg0) {
				
			
				  if(amend==null) {
				 contentPane.setVisible(false);// 设置主窗口内容不显示
					 
					 amend=new StudentAttend(myStudent);
					 System.out.println();
					label.add(amend);
					amend.setLocation(100, 100); //子窗口居中
					amend.setVisible(true); //关闭主窗口后显示内部内部窗体内容
			}
				  
					
				  
			}
			 
		});
		
		menuItem.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 15));
		menu.add(menuItem);
		
		JMenuItem menuItem_1 = new JMenuItem("请  假");
		menuItem_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				/**
				 * 学生添加请假
				 */

				  if(leaved==null) {
				 contentPane.setVisible(false);// 设置主窗口内容不显示
					 
					 leaved=new Leaved();
					label.add(leaved);
					leaved.setLocation(100, 100); //子窗口居中
					leaved.setVisible(true); //关闭主窗口后显示内部内部窗体内容
			}
			}
		});
		menuItem_1.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 15));
		menu.add(menuItem_1);
		
		JMenu menu_1 = new JMenu("学生信息");
		menu_1.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 20));
		menuBar.add(menu_1);
		
		JMenuItem menuItem_2 = new JMenuItem("修改密码");
		menuItem_2.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 15));
		menu_1.add(menuItem_2);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		this.setVisible(true);
		
	}

	

}
